﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppFx.Interpretation.Evaluation.AbstractSyntaxTree;
using System.IO;

namespace AppFx.Interpretation.Evaluation
{
	/// <summary>
	/// Ein EvaluationAnalyzer, der einen AST (AbstractSyntaxTree) erzeugt.
	/// </summary>
	public class ASTEvaluationAnalyzer : EvaluationAnalyzer
	{
		#region Properties

		/// <summary>
		/// Gibt oder setzt den AbstractSyntaxTree.
		/// </summary>
		public Expression AST { get; protected set; }

		#endregion

		#region Constructors

		/// <summary>
		/// Erstellt eine neue Instanz der <see cref="ASTEvaluationAnalyzer"/>-Klasse.
		/// </summary>
		public ASTEvaluationAnalyzer()
		{

		}

		#endregion

		#region Tokens

		public override void EnterIdentifier(PerCederberg.Grammatica.Runtime.Token node)
		{
			base.EnterIdentifier(node);
		}

		public override PerCederberg.Grammatica.Runtime.Node ExitIdentifier(PerCederberg.Grammatica.Runtime.Token node)
		{
			return base.ExitIdentifier(node);
		}

		#endregion

		#region Productions

		public override void EnterExpression(PerCederberg.Grammatica.Runtime.Production node)
		{
			AST = new Expression();
			base.EnterExpression(node);
		}

		public override PerCederberg.Grammatica.Runtime.Node ExitExpression(PerCederberg.Grammatica.Runtime.Production node)
		{
			return base.ExitExpression(node);
		}

		public override void EnterAdditiveExpression(PerCederberg.Grammatica.Runtime.Production node)
		{

			base.EnterAdditiveExpression(node);
		}

		public override PerCederberg.Grammatica.Runtime.Node ExitAdditiveExpression(PerCederberg.Grammatica.Runtime.Production node)
		{
			var m = GetChildValues(node);
			AST.Children.Add(new AdditiveExpression());
			return base.ExitAdditiveExpression(node);
		}

		public override PerCederberg.Grammatica.Runtime.Node ExitValueExpression(PerCederberg.Grammatica.Runtime.Production node)
		{
			return base.ExitValueExpression(node);
		}

		public override PerCederberg.Grammatica.Runtime.Node ExitMemberValueExpression(PerCederberg.Grammatica.Runtime.Production node)
		{
			return base.ExitMemberValueExpression(node);
		}

		public override PerCederberg.Grammatica.Runtime.Node ExitSimpleValueExpression(PerCederberg.Grammatica.Runtime.Production node)
		{
			return base.ExitValueExpression(node);
		}

		public override PerCederberg.Grammatica.Runtime.Node ExitBoolExpression(PerCederberg.Grammatica.Runtime.Production node)
		{
			return base.ExitBoolExpression(node);
		}

		#endregion
	}
}
